<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>

  <script>
    var list = [12, 58, 56, 14, 2, 0, 3, 4, 6, 8, 78, 98];
    // 选择排序
    function sortArray(arr) {
      for (var i = 0; i < arr.length; i++) {
        for (var j = i + 1; j < arr.length; j++) {
          if (arr[i] > arr[j]) {
            var temp = arr[i];
            arr[i] = arr[j];
            arr[j] = temp;
          }
        }
      }
      console.log(arr)
    }
    sortArray(list);

    // 冒泡排序
    var listNumber = [12, 58, 6, 4, 74, 85, 99, 14, 10, 15, 16];

    function sort(arr) {
      for (var i = 0; i < arr.length - 1; i++) {
        for (var j = 0; j < arr.length - i - 1; j++) {
          if (arr[j] > arr[j + 1]) {
            var temp = arr[j];
            arr[j] = arr[j + 1];
            arr[j + 1] = temp;
          }
        }
      }
      console.log(arr)
    }
    sort(listNumber);
    sortArray(list)

  </script>
</body>

</html>
